package com.atguigu.Reducer;
import com.atguigu.Bean.FlowBean;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class FlowReducer extends Reducer<Text, FlowBean, Text, FlowBean> {



    @Override
    protected void reduce(Text key, Iterable<FlowBean> values, Context context) throws IOException, InterruptedException {

        long sum_up = 0;
        long sum_down = 0;

        for (FlowBean bean: values) {
            sum_up += bean.getUpFlow();
            sum_down += bean.getDownFlow();
        }

        context.write(key, new FlowBean(sum_up, sum_down));


    }
}
